package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.PrizeDrawActivity;
import com.sc.nft.entity.dto.AcquisitionActivityDTO;
import com.sc.nft.entity.dto.ActivityApproveDTO;
import com.sc.nft.entity.dto.ActivityListDTO;
import com.sc.nft.entity.vo.PrizeDrawActivityVO;
import com.sc.nft.mapper.PrizeDrawActivityMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

/**
 * 抽奖活动(PrizeDrawActivity)表Dao层
 *
 * @author wwc
 * @since 2023-08-22 14:06:26
 */
@Slf4j
@Repository
public class PrizeDrawActivityDao extends ServiceImpl<PrizeDrawActivityMapper, PrizeDrawActivity> {

    public Page<PrizeDrawActivityVO> activityList(ActivityListDTO activityListDTO) {
        return baseMapper.activityList(activityListDTO.toMp());
    }

    public void approve(ActivityApproveDTO activityApproveDTO) {
        LambdaUpdateWrapper<PrizeDrawActivity> lambdaUpdateWrapper = Wrappers.lambdaUpdate();
        lambdaUpdateWrapper.eq(PrizeDrawActivity::getId, activityApproveDTO.getId());
        lambdaUpdateWrapper.set(PrizeDrawActivity::getAuditStatus, activityApproveDTO.getAuditStatus());
        lambdaUpdateWrapper.set(activityApproveDTO.getAuditStatus().equals(2), PrizeDrawActivity::getRemark, activityApproveDTO.getRemark());
        this.update(lambdaUpdateWrapper);
    }

    public IPage<PrizeDrawActivity> acquisitionActivity(AcquisitionActivityDTO acquisitionActivityDTO) {
        LambdaQueryWrapper<PrizeDrawActivity> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(PrizeDrawActivity::getDaoId, acquisitionActivityDTO.getDaoId());
        lambdaQueryWrapper.eq(PrizeDrawActivity::getAuditStatus,1);
        lambdaQueryWrapper.eq(PrizeDrawActivity::getStatus,1);
        lambdaQueryWrapper.orderByDesc(PrizeDrawActivity::getSort);
        return this.page(acquisitionActivityDTO.toMp(), lambdaQueryWrapper);
    }

}
